<style>
    .well:not(:nth-child(4)){
        display: none;
    }
    .dbq>input{
        width:25%;
        float:left;
    }
    .dim_list input{
        width:20%;
    }
    .label_list{
        width:70%;
        float:right;
    }
    .dim_list{
        margin-bottom:20px;
    }
    .clear{
        clear:both;
    }
    .dim_title{
        height:50px;
        border-bottom:2px solid #468;
        margin-bottom:20px;
    }
    .clear{
        clear:both;
    }
    .dim_title>div:nth-child(1){
        width:20%;
        line-height: 50px;
        font-size:16px;
        font-weight: bold;
        text-align: center;
        float:left;
    }
    .dim_title>.label_list>div:nth-child(1){
        width:20%;
    }
    .dim_title>.label_list>div:nth-child(2){
        width:220px;
    }
    .dim_title>.label_list>div:nth-child(3){
        width:20%;
    }
    .dim_title>.label_list>div:nth-child(4){
        width:20%;
    }
    .dim_title>.label_list>div{
        float:left;
        text-align: center;
        line-height:50px;
        font-size:16px;
        font-weight: bold;
    }
    h2{
        text-align: center;
    }
    .hide{
        display:none;
    }
    .dim_count_title{
        margin-right:20px;
        width:150px;
        float:left;
    }
    .dim_count_select{
        float:left;
    }
    .dim_count_title2{
        margin-left:50px;
        width:300px;
        float:left;
    }
    .textareas textarea{
        width:150px;
    }
    .textareas input{
        width:75px;
    }
    .blue{
        color:blue;
    }
    .dim_count_item form{
        display:inline;
    }
    .dim_count_item textarea{
        height:80px;
    }
</style>
<div class="content">
    <div class="header">
        <h1 class="page-title">修改问卷</h1>
    </div>
    <ul class="breadcrumb">
        <li class="active">修改问卷</li>
    </ul>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="btn-toolbar">
                <button class="btn btn-primary"><i class="icon-list"></i> 基本信息</button>
                <button class="btn btn-primary"><i class="icon-list"></i> 维度</button>
                <button class="btn btn-primary"><i class="icon-list"></i> 输出方式</button>
                <div class="btn-group">
                </div>
            </div>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form action="" method="post">
                            <input type="hidden" name="qu_id" value="<?php echo $que_info['qu_id']; ?>">
                            <label>问卷标题</label>
                            <input type="text" name="qu_title" value="<?php echo $que_info['qu_title']; ?>" class="input-xxlarge">
                            <label>建议起始年龄（月）</label>
                            <input type="number" name="qu_startage" value="<?php echo $que_info['qu_startage']; ?>" class="input-xxlarge">
                            <label>建议结束年龄（月）</label>
                            <input type="number" name="qu_endage" value="<?php echo $que_info['qu_endage']; ?>" class="input-xxlarge">
                            <label>问卷描述</label>
                            <textarea rows="3" name="qu_description" class="input-xxlarge"><?php echo $que_info['qu_description']; ?></textarea>
                            <label>问卷排序(值越大排越前)</label>
                            <input type="text" name="qu_order" value="<?php echo $que_info['qu_order']; ?>" class="input-xxlarge">
                            <label>平均值</label>
                            <input type="number" name="qu_mean" value="<?php echo $que_info['qu_mean']; ?>" class="input-xxlarge">
                            <label>标准差</label>
                            <input type="number" name="qu_deviation" value="<?php echo $que_info['qu_deviation']; ?>" class="input-xxlarge">
                            <label>是否启用</label>
                            <input type="radio" <?php echo $que_info['qu_status']==1?'checked':''; ?> name="qu_status" value="1" class="input-xxlarge">是
                            <input type="radio" <?php echo $que_info['qu_status']==2?'checked':''; ?> name="qu_status" value="2" class="input-xxlarge">否
                            <label></label>
                            <input class="btn btn-primary" type="submit" value="提交" />
                        </form>
                    </div>
                </div>

            </div>
            <div class="well">
                <div class="dim_title">
                    <div>一级维度名称</div>
                    <div class="label_list">
                        <div>二级维度名称</div>
                        <div>计分方式</div>
                        <div>平均值</div>
                        <div>标准差</div>
                    </div>
                    <div class="clear"></div>
                </div>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <input type="hidden" name="qu_id" id="qu_id" value="<?php echo $que_info['qu_id']; ?>">
                        <div class="wd_list">
                        <?php foreach( $dim_list as $key => $val ){ ?>
                        <div class="dim_list">
                            <div class="dbq">
                                <input type="text" name="dim_list[]" class="isdim" dim_id="<?php echo $val['dim_id']; ?>" value="<?php echo $val['dim_name']; ?>" >
                                <div class="label_list">
                                    <input type="text" name="dim_children" class="input-xxlarge" style="opacity:0;">
                                    <select class="dim_scoring" id=""  dim_id="<?php echo $val['dim_id']; ?>" >
                                        <option value="1" <?php echo $val['dim_scoring'] == 1 ? 'selected':''; ?>>原始总分</option>
                                        <option value="2" <?php echo $val['dim_scoring'] == 2 ? 'selected':''; ?>>原始平均分</option>
                                        <option value="3" <?php echo $val['dim_scoring'] == 3 ? 'selected':''; ?>>百分比</option>
                                    </select>
                                    <input type="number" dim_id="<?php echo $val['dim_id']; ?>"  class="dim_mean"  name="" placeholder="平均值" value="<?php echo $val['dim_mean']; ?>">
                                    <input type="number" dim_id="<?php echo $val['dim_id']; ?>"  class="dim_deviation"  name="" placeholder="标准差" value="<?php echo $val['dim_deviation']; ?>">
                                    <a dim_id="<?php echo $val['dim_id']; ?>" class="del_dim" role="button" ><i class="icon-remove"></i></a>
                                </div>
                            </div>
                            <div class="label_list">
                                <div>
                                    <?php foreach( $val['children'] as $k => $v ){ ?>
                                    <input type="text" name="dim_children" dim_id="<?php echo $v['dim_id']; ?>"  class="input-xxlarge dim" value="<?php echo $v['dim_name']; ?>">
                                    <select class="dim_scoring" id=""  dim_id="<?php echo $v['dim_id']; ?>" >
                                        <option value="1" <?php echo $v['dim_scoring'] == 1 ? 'selected':''; ?>>原始总分</option>
                                        <option value="2" <?php echo $v['dim_scoring'] == 2 ? 'selected':''; ?>>原始平均分</option>
                                        <option value="3" <?php echo $v['dim_scoring'] == 3 ? 'selected':''; ?>>百分比</option>
                                    </select>
                                    <input type="number" dim_id="<?php echo $v['dim_id']; ?>"  class="dim_mean"  name="" placeholder="平均值" value="<?php echo $v['dim_mean']; ?>">
                                    <input type="number" dim_id="<?php echo $v['dim_id']; ?>"  class="dim_deviation"  name="" placeholder="标准差" value="<?php echo $v['dim_deviation']; ?>">
                                    <a dim_id="<?php echo $v['dim_id']; ?>" class="del_dim2" role="button" ><i class="icon-remove"></i></a>
                                    <br>
                                    <?php } ?>

                                </div>
                                <button class="btn btn-primary add_bq" dim_id="<?php echo $val['dim_id']; ?>"  >添加二级维度</button>
                            </div>
                            <div class="clear"></div>
                        </div>
                        <?php } ?>
                        </div>
                        <button class="btn btn-primary add_wd">添加一级维度</button>
                    </div>
                </div>
            </div>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <h2>雷达图</h2>
                        <form action="" method="post">
                            <input type="hidden" name="qu_id" value="">
                            <div class="dim_count_title">
                                维度数
                            </div>
                            <select class="dim_count_select" name="" id="">
                                <?php
                                for( $i = 1 ; $i <= $dim_count ; $i++ ){
                                ?>
                                <option value="<?php echo $i; ?>" <?php if( count($dim_radar_is) == $i ){ echo 'selected'; } ?>><?php echo $i; ?></option>
                                <?php } ?>
                            </select>
                            <div class="dim_count_title2">
                            分数上限：<input type="text" id="qu_radar_number" name="" value="<?php echo $que_info['qu_radar_number']; ?>">
                            </div>
                            <div class="clear"></div>
                            <div class="dim_count_list">
                                <?php foreach( $dim_radar_is as $key => $val ){ ?>
                                <div class="dim_count_item" >
                                    <div class="dim_count_title " >
                                        维度<?php echo $key+1; ?>
                                    </div>
                                    <select name="dim_radar_list[]" order="<?php echo $key+1; ?>" qrd_id="<?php echo $val['qrd_id']; ?>" id="">
                                        <option value="0">无</option>
                                        <?php foreach( $dim_radar_list as $k => $v ){ ?>
                                        <option value="<?php echo $v['dim_id'] ?>" <?php if( $val['dim_id'] == $v['dim_id'] ){ echo 'selected'; } ; ?> ><?php echo $v['dim_name']; ?></option>
                                        <?php } ?>
                                    </select>
                                    <div class="clear"></div>
                                </div>
                                <?php } ?>
                                <?php
                                for( $i = count( $dim_radar_is ) + 1 ; $i <= $dim_count ; $i++ ){
                            ?>
                                <div class="dim_count_item hide">
                                    <div class="dim_count_title " >
                                        维度<?php echo $i ; ?>
                                    </div>
                                    <select name="" id="" order="<?php echo $i; ?>">
                                        <option value="0">无</option>
                                        <?php foreach( $dim_radar_list as $key => $val ){ ?>
                                        <option value="<?php echo $val['dim_id'] ?>"><?php echo $val['dim_name']; ?></option>
                                        <?php } ?>
                                    </select>
                                    <div class="clear"></div>
                                </div>
                                <?php } ?>
                            </div>
                        </form>
                    </div>
                    <div class="textareas">
                        <h2>维度评语</h2>
                        <?php foreach( $dim_radar_list as $key => $val ){ ?>
                        <div class="dim_count_item" dim_id="<?php echo $val['dim_id']; ; ?>" >
                            <div class="dim_count_title"><?php echo $val['dim_name']; ?></div>
                            好评：<textarea class="dim_actor"><?php echo $val['dim_actor']; ?></textarea>
                            坏评：<textarea class="dim_bad"><?php echo $val['dim_bad']; ?></textarea>
                            <form method="get" action="<?php echo url("Admin/Index/edit_offer"); ?>">
                            <input type="hidden" name="qu_id" value="<?php echo $val['dim_questionid'];  ?>">
                            <input type="hidden" name="dim_id" value="<?php echo $val['dim_id'];  ?>">
                            建议：<textarea name="dim_offer" class="dim_offer"><?php echo str_replace("<br>","\n",$val['dim_offer']);  ?></textarea>
                            </form>
                            编码：<textarea class="dim_coding"><?php echo $val['dim_coding']; ?></textarea>
                            称呼：<textarea class="dim_appellation"><?php echo $val['dim_appellation']; ?></textarea>
                            字幕云：<input type="file" class="dim_result_img" multiple /> <span class="blue">查看<img class="hide" src="<?php echo base_url.$val['dim_result_img']; ?>" alt=""></span>

                        </div>
                        <br>
                        <?php } ?>
                    </div>
                </div>
                <style>
                    .zmy{
                        width: 100%;
                        height:1000px;
                        background:rgba(0,0,0,0.8);
                        position: fixed;
                        top:0px;
                        left:0px;
                        display: none;
                    }
                    .zmy img{
                        display: block;
                        margin:200px auto;
                    }
                </style>
                <div class="zmy">
                    <img src="" alt="">
                </div>
                <!--输出方式相关js操作-->
                <script src="<?php echo base_url; ?>plugin/imageCompress/jquery.imagecompress.js"></script>
                <script>
                    //字幕云查看
                    $('.blue').click(function (e){
                        $('.zmy').css('display','block')
                        var src = $(this).children("img").attr('src')
                        $('.zmy img').attr("src",src)
                    })
                    $('.zmy').click(function (e){
                        $(this).css('display','none')
                    })
                    //
                    $('.dim_result_img').click(function (e){
                        that = $(this)
                        dim_id = $(this).parent().attr("dim_id");
                    })
                    //替换二维码图
                    $('.dim_result_img').imageCompress({
                        'quality': 50,
                        'onloadStart': function(result){
                        },
                        'onloadEnd': function(result){
                        },
                        'oncompressStart': function(result){
                            if(confirm("确定要替换该图片吗？")){
                                var dim_result_img = $(result).attr('src')
                                that.children('img').attr('src',dim_result_img)
                                console.log(that.next().children('img'))
                                var url =  '<?php echo url("Admin/Index/edit_result_img"); ?>?dim_id=' + dim_id ;
                                var data = {dim_result_img:dim_result_img};
                                $.post(url,data,function (e){

                                },"json")
                            }
                        },
                        'oncompressEnd': function(result){

                        },
                        'callback': function(){
                        }
                    });

                    //多行文本框的回车事件
                    $(".dim_offer").keydown(function(event) {
                        if (event.keyCode == 13) {

                        }
                    })
                    //修改维度码
                    $('.dim_coding').change(function (e){
                        var dim_id = $(this).parent().attr("dim_id");
                        var dim_coding = $(this).val();
                        var url =  '<?php echo url("Admin/Index/edit_coding"); ?>?dim_id=' + dim_id + "&dim_coding=" + dim_coding ;
                        var data = {};
                        $.get(url,data,function (e){

                        },"json")
                    })
                    //修改维度所属的妈妈称呼
                    $('.dim_appellation').change(function (e){
                        var dim_id = $(this).parent().attr("dim_id");
                        var dim_appellation = $(this).val();
                        var url =  '<?php echo url("Admin/Index/edit_appellation"); ?>?dim_id=' + dim_id + "&dim_appellation=" + dim_appellation ;
                        var data = {};
                        $.get(url,data,function (e){

                        },"json")
                    })
                    //维度建议改变时
                    $('.dim_offer').change(function (e){
//                        var dim_id = $(this).parent().attr("dim_id");
//                        var dim_offer = $(this).val();
//                        var url =  '<?php echo url("Admin/Index/edit_offer"); ?>?dim_id=' + dim_id + "&dim_offer=" + dim_offer ;
//                        var data = {};
//                        $.get(url,data,function (e){
//
//                        },"json")
                        $(this).parent("form").submit();
                    })
                    //维度评语改变时
                    $('.dim_actor').change(function (e){
                        var dim_id = $(this).parent().attr("dim_id");
                        var dim_actor = $(this).val();
                        var url =  '<?php echo url("Admin/Index/edit_actor"); ?>?dim_id=' + dim_id + "&dim_actor=" + dim_actor ;
                        var data = {};
                        $.get(url,data,function (e){

                        },"json")
                    })
                    $('.dim_bad').change(function (e){
                        var dim_id = $(this).parent().attr("dim_id");
                        var dim_actor = $(this).val();
                        var url =  '<?php echo url("Admin/Index/edit_bad"); ?>?dim_id=' + dim_id + "&dim_bad=" + dim_actor ;
                        var data = {};
                        $.get(url,data,function (e){

                        },"json")
                    })
                    //维度数改变时，更改其维度数量
                    $('.dim_count_select').change(function (e){
                        var item_val = $(this).val();
                        $('.dim_count_list  .dim_count_item').each(function (e){
                            if( item_val > e ){
                                $(this).removeClass('hide')
                            } else {
                                $(this).addClass('hide')
                            }
                        })
                    })

                    //维度改变时，更改其维度id
                    $('.dim_count_item select').change(function (e){
                        var order = $(this).attr('order')
                        var dim_id = $(this).val()
                        var qu_id = $("#qu_id").val();
                        //如果是修改的
                        //如果是添加的
                        if( $(this).attr('qrd_id') ){
                            var qrd_id = $(this).attr("qrd_id")
                            url =  '<?php echo url("Admin/Index/add_dim_radar"); ?>?dim_id=' + dim_id + "&qu_id=" + qu_id + "&order=" + order + "&qrd_id=" + qrd_id ;
                        } else {
                            url =  '<?php echo url("Admin/Index/add_dim_radar"); ?>?dim_id=' + dim_id + "&qu_id=" + qu_id + "&order=" + order ;
                        }
                        $.post(url,function (e){
                            console.log(e)
                        },'json')
                    })

                    //分数上限改变时，进行更改
                    $('#qu_radar_number').change(function (e){
                        var number = $(this).val()
                        var qu_id = $('#qu_id').val()
                        url =  '<?php echo url("Admin/Index/questionnaire_edit_radar_number"); ?>?number=' + number + "&qu_id=" + qu_id ;
                        $.get( url , function (e){
                            console.log(e)
                        },"json")
                    })


                </script>
            </div>
            <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">Delete Confirmation</h3>
                </div>
                <div class="modal-body">

                    <p class="error-text"><i class="icon-warning-sign modal-icon"></i></p>

                </div>
                <!--维度相关js操作-->
                <script>
                    $(document).on('click','.del_dim',function (e){
                        if(confirm("确定要删除该维度吗？")){
                            dim_id = $(this).attr('dim_id')
                            qu_id = $('#qu_id').val()

                            location.href = "<?php echo url('Admin/Index/del_dim'); ?>?dim_id=" + dim_id + "&qu_id=" + qu_id
                        }
                    })
                    $(document).on('click','.del_dim2',function (e){
                        if(confirm("确定要删除该维度吗？")){
                            dim_id = $(this).attr('dim_id')
                            qu_id = $('#qu_id').val()

                            location.href = "<?php echo url('Admin/Index/del_dim'); ?>?dim_id=" + dim_id + "&qu_id=" + qu_id

                        }
                    })
                    //切换模块
                    $('.btn-toolbar .btn-primary').click(function (){
                        var i = $('.btn-toolbar .btn-primary').index(this)
                        $('.well').hide()
                        $('.well').eq(i).show()
                    })
                    //添加维度
                    $('.add_wd').click(function (){
                        var dim_name = "一级维度" + ($('.isdim').length+1) ;//目前第几个维度
                        var qu_id = $('#qu_id').val();//获取问卷id
                        var url = '<?php echo url("Admin/Index/add_dim"); ?>?dim_name=' + dim_name + "&dim_questionid=" + qu_id
                        var data = {}
                        $.get(url,data,function (e){
                            var str = '<div class="dim_list"><input type="text" name="dim_list[]" dim_id="'+ e +'" value="' + dim_name + '（可重命名）" class="dim input-xxlarge isdim"><div class="label_list"><div></div><button class="btn btn-primary add_bq" dim_id="'+ e +'">添加二级维度</button></div><div class="clear"></div></div>';
                            $('.wd_list').append(str);
                        },'json')
                        return false;
                    })
                    //维度重命名
                    $(document).on('focus','.dim',function (){
                        isval = $(this).val()
                    })
                    $(document).on('blur','.dim',function (){

                        var that = $(this)
                        var dim_name = $(this).val()

                        //判断如果
                        if(dim_name == isval)
                        {
                            return false;
                        }

                        var dim_id = $(this).attr('dim_id')
                        var url = '<?php echo url("Admin/Index/edit_dim"); ?>?dim_name=' + dim_name + "&dim_id=" + dim_id
                        var data = {}
                        $.get(url,data,function (e){
                            if( e != 1 ){
                                console.log("修改失败，请重新尝试")
                            }
                        },'json')
                    })


                    //添加小维度
                    $(document).on('click','.add_bq',function (){
                        var that = $(this)
                        var dim_name = "二级维度" + ($(this).prev().children('.dim').length+1) ;//目前第几个维度
                        var qu_id = $('#qu_id').val();//获取问卷id
                        var dim_father = $(this).attr('dim_id');//获取小维度的父维度id

                        var url = '<?php echo url("Admin/Index/add_dim"); ?>?dim_name=' + dim_name + "&dim_questionid=" + qu_id + "&dim_father=" + dim_father
                        var data = {}
                        $.get(url,data,function (e){
                            var str = '<input type="text" name="dim_children" dim_id="'+ e +'"  class="input-xxlarge dim" value="' + dim_name + '（可重命名）"> <select class="dim_scoring" id=""  dim_id="'+ e +'" ><option value="1">原始总分</option><option value="2" >原始平均分</option><option value="3" >百分比</option></select> <input type="number" dim_id="'+ e +'" class="dim_mean"  name="" placeholder="平均值" value="0"> <input type="number" dim_id="'+ e +'" class="dim_deviation"  name="" placeholder="标准差" value="0"> <a dim_id="'+ e +'" class="del_dim" role="button" ><i class="icon-remove"></i></a><br>';
                            that.prev().append(str);
                        },'json')
                        return false;
                    })

                    //小维度的计分方式修改
                    $(document).on('change','.dim_scoring',function (){

                        var that = $(this)
                        var dim_scoring = $(this).val()

                        var dim_id = $(this).attr('dim_id')
                        var url = '<?php echo url("Admin/Index/edit_dim_scoring"); ?>?dim_scoring=' + dim_scoring + "&dim_id=" + dim_id
                        var data = {}
                        $.get(url,data,function (e){
                            if( e == 1 ) {
//                                if( dim_scoring  == 3 ){
//                                    $(that).next().prop("disabled",false)
//                                    $(that).next().next().prop("disabled",false)
//                                } else {
//                                    $(that).next().prop("disabled",true)
//                                    $(that).next().next().prop("disabled",true)
//                                }
                            } else {
                                console.log("修改失败，请重新尝试")
                            }
                        },'json')
                    })

                    //小维度的平均值修改
                    $(document).on('blur','.dim_mean',function (){

                        var that = $(this)
                        var dim_mean = $(this).val()

                        var dim_id = $(this).attr('dim_id')
                        var url = '<?php echo url("Admin/Index/edit_dim_mean"); ?>?dim_mean=' + dim_mean + "&dim_id=" + dim_id
                        var data = {}
                        $.get(url,data,function (e){
                            if( e != 1 ) {
                                console.log("修改失败，请重新尝试")
                            }
                        },'json')
                    })

                    //小维度的平均值修改
                    $(document).on('blur','.dim_deviation',function (){

                        var that = $(this)
                        var dim_deviation = $(this).val()

                        var dim_id = $(this).attr('dim_id')
                        var url = '<?php echo url("Admin/Index/edit_dim_deviation"); ?>?dim_deviation=' + dim_deviation + "&dim_id=" + dim_id
                        var data = {}
                        $.get(url,data,function (e){
                            if( e != 1 ) {
                                console.log("修改失败，请重新尝试")
                            }
                        },'json')
                    })
                </script>